﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Xml.Serialization;
using System.IO;
using System.Web.Security;
using System.Xml;

namespace NasuTek.Shion.GenuineAdvantage
{
    public class Validator
    {
        static Configuration config;

        static public bool ValidateHashes(bool debug)
        {
            GetConfig(debug);
            //Name:Product:Random Password For Product
            string data = config.Name + ":NasuTek Shion(Beta):jhjs^^h^%$TR$RF$#R^654T^%R%F%^&*(";

            string returnedhash = FormsAuthentication.HashPasswordForStoringInConfigFile(data, "MD5");
            if (returnedhash == config.Hash) { return true; }
            else { return false; }
        }

        static public void GetConfig(bool debug)
        {
            if (debug == false)
            {
                if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Shion6.xml")))
                {
                    XmlSerializer x = new XmlSerializer(typeof(Configuration));
                    FileStream fs = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Shion6.xml"), FileMode.Open);
                    config = (Configuration)x.Deserialize(XmlReader.Create(fs));
                    fs.Close();
                }
                else { config = new Configuration(); }
            }
            else
            {
                if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Shion6-debug.xml")))
                {
                    XmlSerializer x = new XmlSerializer(typeof(Configuration));
                    FileStream fs = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Shion6-debug.xml"), FileMode.Open);
                    config = (Configuration)x.Deserialize(XmlReader.Create(fs));
                    fs.Close();
                }
                else { config = new Configuration(); }
            }
        }
    }
}